package learn.actuator;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 命名有要求 以 HealthIndicator 结尾
 * @Author yxc
 * @Date 2022/1/12
 */

//@Component
public class MyComHealthIndicator extends AbstractHealthIndicator {

    /**
     * 真实的检查方法
     *
     * @param builder
     * @throws Exception
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Map<String, Object> map = new HashMap<>();
        // 检查完成
        if (1 == 1) {
            //健康
//            builder.up();
            builder.status(Status.UP);
            map.put("count", 1);
            map.put("ms", 100);
        } else {
            //不健康
//            builder.down();
            builder.status(Status.OUT_OF_SERVICE);
            map.put("err", "连接超时");
            map.put("ms", 3000);
        }
        builder.withDetails(map);
    }
}
